# 整体流程

1. 应用接入方到 TAPD 开放平台(https://o.tapd.woa.com)创建应用
2. 与 anyechen 对接,修改支持按用户授权
3. 参考下面指引开发

1
2
3
4

# 理解 OAuth2.0

# 接入方使用过程

# 1. 拼接URL

# 格式:

https://tapd.woa.com/oauth/?response_type=code&client_id=%s&redirect_uri=%s&scope=%s&state=%s&auth_by=%s 注意:

  1. 取多个 scope,使用空格分隔,如story bug
  2. 里面参数要经过 urlencode。比如 scope 取 story bug ,urlencode 后则是 story%20bug 或者 story+bug
  3. auth_by 目前支持取 user

# 示例:

https://tapd.woa.com/oauth/?response_type=code&client_id=demo&redirect_uri=http://lion.oa.com/~anyechen/code/php/oauth_demo/hey.php&scope=bug%20story&auth_by=user&state=random_string

# 2. 浏览器打开拼接好的 URL

图片描述

# 3. 用户确认授权,点击“同意授权”

图片描述

# 4. 跳转到上面配置的跳转 URL,传递 code 参数及授权的项目 resource 参数,和回传 state 参数

# 例子:

http://lion.oa.com/~anyechen/code/php/oauth_demo/hey.php?code=8bb30b3192bc1bdbbee311a2bc21113723db7777&state=random_string&resource=%7B%22type%22%3A%22user%22%2C%22user_id%22%3A%221000142421%22%7D'

Array
(
    [code] => 8bb30b3192bc1bdbbee311a2bc21113723db7777
    [state] => random_string
    [resource] => {"type":"user","user_id":"1000142421"}
)
1
2
3
4
5
6

# 注意

  1. 返回的 resource ,会带上当前授权的项目ID,只能获取这个项目下的数据
  2. code 的有效期为五分钟

# 5. 使用 code 获取 access_token

# 请求 URL

https://apiv2.tapd.tencent.com/tokens/request_token

# 请求方法

POST

# 参数要求

# POST 参数

参数 说明
grant_type 必须取值 authorization_code
redirect_uri 为配置的跳转 uri
code 为从链接参数上取得的 code

# 其它参数

假设发放的 client_idAladdinclient_secretopen sesame,则处理步骤举例如下:

  1. Aladdin:open sesame 通过 BASE64 编码为:QWxhZGRpbjpvcGVuIHNlc2FtZQ==
  2. 写入 HTTP 头部的 Authorization 信息为:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
1

# 返回

返回参数 参数说明
access_token 访问 API 的凭据
expires_in 有效时长,单位为秒
token_type 凭据类型,都是 Bearer
scope 接口范围
resource 项目权限范围
now 服务器当前时间

# 示例

# 示例请求

curl -u "client_id:client_secret" -d "grant_type=authorization_code&redirect_uri=http://lion.oa.com/~anyechen/code/php/oauth_demo/hey.php&code=82a65674bd67e26e034967f5d72e17e8a4b6d395" "https://apiv2.tapd.tencent.com/tokens/request_token"

# 示例返回

{
    "status": 1,
    "data": {
        "access_token": "7152e30d9c5b1310df6be03d88d714aaf687a595",
        "expires_in": 7200,
        "token_type": "Bearer",
        "scope": "bug story",
        "resource": {
            "type": "user",
            "workspace_id": 1000142421
        },
        "now": "2019-06-04 16:07:51"
    },
    "info": "success"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 6. 使用 access_token 做为参数,调用接口

只需要在 http header 传 access_token 参数,如: curl -H 'Authorization: Bearer ACCESS_TOKEN' 'https://apiv2.tapd.tencent.com/bugs?workspace_id=10022001&fields=id,title'

上次更新: 2023-03-20 17:01:20